<template>
  <div class="search-history">
    <van-cell title="搜索历史">
      <div v-if="isDeleteShow">
        <span @click="$emit('clear-all-histories')">全部删除</span>
        &nbsp;&nbsp;
        <span @click="isDeleteShow=false">完成</span>
      </div>
      <van-icon @click="isDeleteShow=true" name="delete" v-else></van-icon>
    </van-cell>

    <van-cell
      :key="index"
      :title="item"
      @click="onSearchHistoryItems(item,index)"
      v-for="item,index in SearchHistories"
    >
      <van-icon name="close" v-show="isDeleteShow"></van-icon>
    </van-cell>
  </div>
</template>

<script>
export default {
  name: 'SearchHistory',
  props: {
    SearchHistories: {
      typeo: Array,
      required: true
    }
  },
  data () {
    return {
      isDeleteShow: false
    }
  },
  created () {
  },
  methods: {
    onSearchHistoryItems (item, index) {
      if (this.isDeleteShow) {
        // 删除状态
        this.SearchHistories.splice(index, 1)
      } else {
        // 非删除状态
        this.$emit('search', item)
      }
    }

  }
}
</script>

<style lang="less" scoped>
</style>